home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / textfile / mac_faqs / comp_faq / part2 < prev   
Encoding:
Internet Message Format  |  1995-01-01  |  39.6 KB

  1. Xref: bloom-picayune.mit.edu comp.compression:4949 news.answers:3737
  2. Path: bloom-picayune.mit.edu!snorkelwacker.mit.edu!news.media.mit.edu!micro-heart-of-gold.mit.edu!wupost!darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!corton!chorus!chorus.fr
  3. From: jloup@chorus.fr (Jean-loup Gailly)
  4. Newsgroups: comp.compression,news.answers
  5. Subject: comp.compression Frequently Asked Questions (part 2/2)
  6. Summary: *** READ THIS BEFORE POSTING ***
  7. Keywords: data compression, FAQ
  8. Message-ID: <compr2_29oct92@chorus.fr>
  9. Date: 30 Oct 92 13:11:19 GMT
  10. Expires: 10 Dec 92 16:17:20 GMT
  11. References: <compr1_29oct92@chorus.fr>
  12. Sender: news@chorus.chorus.fr
  13. Reply-To: jloup@chorus.fr
  14. Followup-To: comp.compression
  15. Lines: 800
  16. Approved: news-answers-request@MIT.Edu
  17. Supersedes: <compr2_2oct92@chorus.fr>
  18.  
  19. Archive-name: compression-faq/part2
  20. Last-modified: Oct 2nd, 1992
  21.  
  22. This file is part 2 of a set of Frequently Asked Questions for the
  23. groups comp.compression and comp.compression.research.
  24.  
  25. If you don't want to see this FAQ regularly, please add the subject
  26. line to your kill file. If you have corrections or suggestions for
  27. this FAQ, send them to Jean-loup Gailly <jloup@chorus.fr>.  Thank you.
  28.  
  29. Contents
  30. ========
  31.  
  32. (Long) introductions to data compression techniques
  33.  
  34. [70] Introduction to data compression (long)
  35.        Huffman and Related Compression Techniques
  36.        Arithmetic Coding
  37.        Substitutional Compressors
  38.           The LZ78 family of compressors
  39.           The LZ77 family of compressors
  40.  
  41. [71] Introduction to MPEG (long)
  42.        What is MPEG?
  43.        Does it have anything to do with JPEG?
  44.        Then what's JBIG and MHEG?
  45.        What has MPEG accomplished?
  46.        So how does MPEG I work?
  47.        What about the audio compression?
  48.        So how much does it compress?
  49.        What's phase II?
  50.        When will all this be finished?
  51.        How do I join MPEG?
  52.        How do I get the documents, like the MPEG I draft?
  53.  
  54. [72] What is wavelet theory?
  55. [73] What is the theoretical compression limit?
  56. [74] Introduction to JBIG
  57.  
  58. [99] Acknowledgments
  59.  
  60. Search for "Subject: [#]" to get to question number # quickly. Some news
  61. readers can also take advantage of the message digest format used here.
  62.  
  63. ------------------------------------------------------------------------------
  64.  
  65. Subject: [70] Introduction to data compression (long)
  66.  
  67.  
  68. Written by Peter Gutmann <pgut1@cs.aukuni.ac.nz>.
  69.  
  70.  Huffman and Related Compression Techniques
  71.  ------------------------------------------
  72.  
  73.   *Huffman compression* is a statistical data compression technique which 
  74. gives a reduction in the average code length used to represent the symbols of 
  75. a alphabet.  The Huffman code is an example of a code which is optimal in the 
  76. case where all symbols probabilities are integral powers of 1/2.  A Huffman 
  77. code can be built in the following manner:
  78.  
  79.   (1) Rank all symbols in order of probability of occurrence.
  80.     
  81.   (2) Successively combine the two symbols of the lowest probability to form
  82.       a new composite symbol; eventually we will build a binary tree where
  83.       each node is the probability of all nodes beneath it.
  84.  
  85.   (3) Trace a path to each leaf, noticing the direction at each node.
  86.  
  87.   For a given frequency distribution, there are many possible Huffman codes,
  88. but the total compressed length will be the same. It is possible to
  89. define a 'canonical' Huffman tree, that is, pick one of these alternative
  90. trees. Such a canonical tree can then be represented very compactly, by
  91. transmitting only the bit length of each code. This technique is used
  92. in most archivers (pkzip, lha, zoo, arj, ...).
  93.  
  94.  
  95.   A technique related to Huffman coding is *Shannon-Fano coding*, which was 
  96. suggested by Shannon and Weaver in 1949 and modified by Fano in 1961.  It 
  97. works as follows:
  98.  
  99.   (1) Divide the set of symbols into two equal or almost equal subsets
  100.       based on the probability of occurrence of characters in each
  101.       subset.  The first subset is assigned a binary zero, the second
  102.       a binary one.
  103.  
  104.   (2) Repeat step (1) until all subsets have a single element.
  105.  
  106. The algorithm used to create the Huffman codes is bottom-up, and the
  107. one for the Shannon-Fano codes is top-down. Huffman encoding always
  108. generates optimal codes, Shannon-Fano sometimes uses a few more bits.
  109.  
  110.  
  111.  Arithmetic Coding
  112.  -----------------
  113.  
  114.   It would appear that Huffman or Shannon-Fano coding is the perfect
  115. means of compressing data.  However, this is *not* the case.  As
  116. mentioned above, these coding methods are optimal when and only when
  117. the symbol probabilities are integral powers of 1/2, which is usually
  118. not the case.
  119.  
  120.   The technique of *arithmetic coding* does not have this restriction:
  121. It achieves the same effect as treating the message as one single unit
  122. (a technique which would, for Huffman coding, require enumeration of
  123. every single possible message), and thus attains the theoretical
  124. entropy bound to compression efficiency for any source.
  125.  
  126.   Arithmetic coding works by representing a number by an interval of real 
  127. numbers between 0 and 1.  As the message becomes longer, the interval needed 
  128. to represent it becomes smaller and smaller, and the number of bits needed to 
  129. specify that interval increases.  Successive symbols in the message reduce 
  130. this interval in accordance with the probability of that symbol. The more
  131. likely symbols reduce the range by less, and thus add fewer bits to the   
  132. message.
  133.  
  134.      1                                             Codewords
  135.     +-----------+-----------+-----------+           /-----\
  136.     |           |8/9 YY     |  Detail   |<- 31/32    .11111
  137.     |           +-----------+-----------+<- 15/16    .1111
  138.     |    Y      |           | too small |<- 14/16    .1110
  139.     |2/3        |    YX     | for text  |<- 6/8      .110
  140.     +-----------+-----------+-----------+
  141.     |           |           |16/27 XYY  |<- 10/16    .1010
  142.     |           |           +-----------+
  143.     |           |    XY     |           |
  144.     |           |           |   XYX     |<- 4/8      .100
  145.     |           |4/9        |           |
  146.     |           +-----------+-----------+
  147.     |           |           |           |
  148.     |    X      |           |   XXY     |<- 3/8      .011
  149.     |           |           |8/27       |
  150.     |           |           +-----------+
  151.     |           |    XX     |           |
  152.     |           |           |           |<- 1/4      .01
  153.     |           |           |   XXX     |
  154.     |           |           |           |
  155.     |0          |           |           |
  156.     +-----------+-----------+-----------+
  157.  
  158.   As an example of arithmetic coding, lets consider the example of two
  159. symbols X and Y, of probabilities 0.66 and 0.33. To encode this message, we
  160. examine the first symbol: If it is a X, we choose the lower partition; if
  161. it is a Y, we choose the upper partition.  Continuing in this manner for
  162. three symbols, we get the codewords shown to the right of the diagram above
  163. - they can be found by simply taking an appropriate location in the
  164. interval for that particular set of symbols and turning it into a binary
  165. fraction. In practice, it is also necessary to add a special end-of-data
  166. symbol, which is not represented in this simpe example.
  167.         
  168.   In this case the arithmetic code is not completely efficient, which is due 
  169. to the shortness of the message - with longer messages the coding efficiency 
  170. does indeed approach 100%.
  171.  
  172.   Now that we have an efficient encoding technique, what can we do with it? 
  173. What we need is a technique for building a model of the data which we can 
  174. then use with the encoder.  The simplest model is a fixed one, for example a 
  175. table of standard letter frequencies for English text which we can then use 
  176. to get letter probabilities.  An improvement on this technique is to use an 
  177. *adaptive model*, in other words a model which adjusts itself to the data 
  178. which is being compressed as the data is compressed.  We can convert the 
  179. fixed model into an adaptive one by adjusting the symbol frequencies after 
  180. each new symbol is encoded, allowing the model to track the data being 
  181. transmitted.  However, we can do much better than that.
  182.  
  183. Using the symbol probabilities by themselves is not a particularly good
  184. estimate of the true entropy of the data: We can take into account
  185. intersymbol probabilities as well.  The best compressors available today
  186. take this approach: DMC (Dynamic Markov Coding) starts with a zero-order
  187. Markov model and gradually extends this initial model as compression
  188. progresses; PPM (Prediction by Partial Matching) looks for a match of the
  189. text to be compressed in an order-n context.  If no match is found, it
  190. drops to an order n-1 context, until it reaches order 0.  Both these
  191. techniques thus obtain a much better model of the data to be compressed,
  192. which, combined with the use of arithmetic coding, results in superior
  193. compression performance.
  194.  
  195.   So if arithmetic coding-based compressors are so powerful, why are they not 
  196. used universally?  Apart from the fact that they are relatively new and 
  197. haven't come into general use too much yet, there is also one major concern:  
  198. The fact that they consume rather large amounts of computing resources, both 
  199. in terms of CPU power and memory.  The building of sophisticated models for 
  200. the compression can chew through a fair amount of memory (especially in the 
  201. case of DMC, where the model can grow without bounds); and the arithmetic 
  202. coding itself involves a fair amount of number crunching.
  203. There is however an alternative approach, a class of compressors generally 
  204. referred to as *substitutional* or *dictionary-based compressors*.
  205.  
  206.  Substitutional Compressors
  207.  --------------------------
  208.  
  209.   The basic idea behind a substitutional compressor is to replace an 
  210. occurrence of a particular phrase or group of bytes in a piece of data with a 
  211. reference to a previous occurrence of that phrase.  There are two main 
  212. classes of schemes, named after Jakob Ziv and Abraham Lempel, who first 
  213. proposed them in 1977 and 1978.
  214.  
  215. <The LZ78 family of compressors>
  216.  
  217.   LZ78-based schemes work by entering phrases into a *dictionary* and then, 
  218. when a repeat occurrence of that particular phrase is found, outputting the 
  219. dictionary index instead of the phrase.  There exist several compression 
  220. algorithms based on this principle, differing mainly in the manner in which 
  221. they manage the dictionary.  The most well-known scheme (in fact the most 
  222. well-known of all the Lempel-Ziv compressors, the one which is generally (and 
  223. mistakenly) referred to as "Lempel-Ziv Compression"), is Terry Welch's LZW 
  224. scheme, which he designed in 1984 for implementation in hardware for high- 
  225. performance disk controllers.
  226.  
  227. Input string: /WED/WE/WEE/WEB
  228.  
  229. Character input:    Code output:    New code value and associated string:
  230.     /W                  /                   256 = /W
  231.     E                   W                   257 = WE
  232.     D                   E                   258 = ED
  233.     /                   D                   259 = D/
  234.     WE                  256                 260 = /WE
  235.     /                   E                   261 = E/
  236.     WEE                 260                 262 = /WEE
  237.     /W                  261                 263 = E/W
  238.     EB                  257                 264 = WEB
  239.     <END>               B
  240.     
  241.   LZW starts with a 4K dictionary, of which entries 0-255 refer to individual 
  242. bytes, and entries 256-4095 refer to substrings.  Each time a new code is 
  243. generated it means a new string has been parsed.  New strings are generated 
  244. by appending the current character K to the end of an existing string w.  The 
  245. algorithm for LZW compression is as follows:
  246.  
  247.   set w = NIL
  248.   loop
  249.       read a character K
  250.       if wK exists is in the dictionary
  251.           w = wK
  252.       else
  253.           output the code for w
  254.           add wK to the string table
  255.           w = K
  256.   endloop
  257.  
  258.   A sample run of LZW over a (highly redundant) input string can be seen in 
  259. the diagram above.  The strings are built up character-by-character starting 
  260. with a code value of 256.  LZW decompression takes the stream of codes and 
  261. uses it to exactly recreate the original input data.  Just like the 
  262. compression algorithm, the decompressor adds a new string to the dictionary 
  263. each time it reads in a new code.  All it needs to do in addition is to 
  264. translate each incoming code into a string and send it to the output.  A 
  265. sample run of the LZW decompressor is shown in below.
  266.  
  267. Input code: /WED<256>E<260><261><257>B
  268.  
  269. Input code:        Output string:     New code value and associated string:
  270.     /                  /            
  271.     W                  W                      256 = /W
  272.     E                  E                      257 = WE
  273.     D                  D                      258 = ED
  274.     256                /W                     259 = D/
  275.     E                  E                      260 = /WE
  276.     260                /WE                    261 = E/
  277.     261                E/                     262 = /WEE
  278.     257                WE                     263 = E/W
  279.     B                  B                      264 = WEB
  280.            
  281.   The most remarkable feature of this type of compression is that the entire 
  282. dictionary has been transmitted to the decoder without actually explicitly 
  283. transmitting the dictionary.  At the end of the run, the decoder will have a 
  284. dictionary identical to the one the encoder has, built up entirely as part of 
  285. the decoding process.
  286.     LZW is more commonly encountered today in a variant known as LZC, after 
  287. its use in the UNIX "compress" program.  In this variant, pointers do not 
  288. have a fixed length.  Rather, they start with a length of 9 bits, and then 
  289. slowly grow to their maximum possible length once all the pointers of a 
  290. particular size have been used up.  Furthermore, the dictionary is not frozen 
  291. once it is full as for LZW - the program continually monitors compression 
  292. performance, and once this starts decreasing the entire dictionary is 
  293. discarded and rebuilt from scratch.  More recent schemes use some sort of 
  294. least-recently-used algorithm to discard little-used phrases once the 
  295. dictionary becomes full rather than throwing away the entire dictionary.  
  296.  
  297. Finally, not all schemes build up the dictionary by adding a single new 
  298. character to the end of the current phrase. An alternative technique is to 
  299. concatenate the previous two phrases (LZMW), which results in a faster 
  300. buildup of longer phrases than the character-by-character buildup of the 
  301. other methods.  The disadvantage of this method is that a more sophisticated 
  302. data structure is needed to handle the dictionary.
  303.  
  304. [A good introduction to LZW, MW, AP and Y coding is given in the yabba
  305. package. For ftp information, see question 2 in part one, file type .Y]
  306.  
  307.  
  308. <The LZ77 family of compressors>
  309.  
  310.   LZ77-based schemes keep track of the last n bytes of data seen, and when a 
  311. phrase is encountered that has already been seen, they output a pair of 
  312. values corresponding to the position of the phrase in the previously-seen 
  313. buffer of data, and the length of the phrase.  In effect the compressor moves 
  314. a fixed-size *window* over the data (generally referred to as a *sliding 
  315. window*), with the position part of the (position, length) pair referring to 
  316. the position of the phrase within the window.  The most commonly used 
  317. algorithms are derived from the LZSS scheme described by James Storer and 
  318. Thomas Szymanski in 1982.  In this the compressor maintains a window of size 
  319. N bytes and a *lookahead buffer* the contents of which it tries to find a 
  320. match for in the window:
  321.  
  322.   while( lookAheadBuffer not empty )
  323.       {
  324.       get a pointer ( position, match ) to the longest match in the window
  325.           for the lookahead buffer;
  326.  
  327.       if( length > MINIMUM_MATCH_LENGTH )
  328.           {
  329.           output a ( position, length ) pair;
  330.           shift the window length characters along;
  331.           }
  332.       else
  333.           {
  334.           output the first character in the lookahead buffer;
  335.           shift the window 1 character along;
  336.           }
  337.       }
  338.         
  339.   Decompression is simple and fast:  Whenever a ( position, length ) pair is 
  340. encountered, go to that ( position ) in the window and copy ( length ) bytes 
  341. to the output.
  342.  
  343.   Sliding-window-based schemes can be simplified by numbering the input text
  344. characters mod N, in effect creating a circular buffer.  The sliding window
  345. approach automatically creates the LRU effect which must be done explicitly in
  346. LZ78 schemes.  Variants of this method apply additional compression to the
  347. output of the LZSS compressor, which include a simple variable-length code
  348. (LZB), dynamic Huffman coding (LZH), and Shannon-Fano coding (ZIP 1.x)), all
  349. of which result in a certain degree of improvement over the basic scheme,
  350. especially when the data are rather random and the LZSS compressor has little
  351. effect.
  352.   Recently an algorithm was developed which combines the ideas behind LZ77 and
  353. LZ78 to produce a hybrid called LZFG.  LZFG uses the standard sliding window,
  354. but stores the data in a modified trie data structure and produces as output
  355. the position of the text in the trie.  Since LZFG only inserts complete
  356. *phrases* into the dictionary, it should run faster than other LZ77-based
  357. compressors.
  358.  
  359. All popular archivers (arj, lha, zip, zoo) are variations on the LZ77 theme.
  360.  
  361. ------------------------------------------------------------------------------
  362.  
  363. Subject: [71] Introduction to MPEG (long)
  364.  
  365.  
  366. Written by Mark Adler <madler@cco.caltech.edu>.
  367.  
  368. Q. What is MPEG?
  369. A. MPEG is a group of people that meet under ISO (the International
  370.    Standards Organization) to generate standards for digital video
  371.    (sequences of images in time) and audio compression.  In particular,
  372.    they define a compressed bit stream, which implicitly defines a
  373.    decompressor.  However, the compression algorithms are up to the
  374.    individual manufacturers, and that is where proprietary advantage
  375.    is obtained within the scope of a publicly available international
  376.    standard.  MPEG meets roughly four times a year for roughly a week
  377.    each time.  In between meetings, a great deal of work is done by
  378.    the members, so it doesn't all happen at the meetings.  The work
  379.    is organized and planned at the meetings.
  380.  
  381. Q. So what does MPEG stand for?
  382. A. Moving Pictures Experts Group.
  383.  
  384. Q. Does it have anything to do with JPEG?
  385. A. Well, it sounds the same, and they are part of the same subcommittee
  386.    of ISO along with JBIG and MHEG, and they usually meet at the same
  387.    place at the same time.  However, they are different sets of people
  388.    with few or no common individual members, and they have different
  389.    charters and requirements.  JPEG is for still image compression.
  390.  
  391. Q. Then what's JBIG and MHEG?
  392. A. Sorry I mentioned them. Ok, I'll simply say that JBIG is for binary
  393.    image compression (like faxes), and MHEG is for multi-media data
  394.    standards (like integrating stills, video, audio, text, etc.).
  395.    For an introduction to JBIG, see question 74 below.
  396.  
  397. Q. Ok, I'll stick to MPEG.  What has MPEG accomplished?
  398. A. So far (as of January 1992), they have completed the "Committee
  399.    Draft" of MPEG phase I, colloquially called MPEG I.  It defines
  400.    a bit stream for compressed video and audio optimized to fit into
  401.    a bandwidth (data rate) of 1.5 Mbits/s.  This rate is special
  402.    because it is the data rate of (uncompressed) audio CD's and DAT's.
  403.    The draft is in three parts, video, audio, and systems, where the
  404.    last part gives the integration of the audio and video streams
  405.    with the proper timestamping to allow synchronization of the two.
  406.    They have also gotten well into MPEG phase II, whose task is to
  407.    define a bitstream for video and audio coded at around 3 to 10
  408.    Mbits/s.
  409.  
  410. Q. So how does MPEG I work?
  411. A. First off, it starts with a relatively low resolution video
  412.    sequence (possibly decimated from the original) of about 352 by
  413.    240 frames by 30 frames/s (US--different numbers for Europe),
  414.    but original high (CD) quality audio.  The images are in color,
  415.    but converted to YUV space, and the two chrominance channels
  416.    (U and V) are decimated further to 176 by 120 pixels.  It turns
  417.    out that you can get away with a lot less resolution in those
  418.    channels and not notice it, at least in "natural" (not computer
  419.    generated) images.
  420.  
  421.    The basic scheme is to predict motion from frame to frame in the
  422.    temporal direction, and then to use DCT's (discrete cosine
  423.    transforms) to organize the redundancy in the spatial directions.
  424.    The DCT's are done on 8x8 blocks, and the motion prediction is
  425.    done in the luminance (Y) channel on 16x16 blocks.  In other words,
  426.    given the 16x16 block in the current frame that you are trying to
  427.    code, you look for a close match to that block in a previous or
  428.    future frame (there are backward prediction modes where later
  429.    frames are sent first to allow interpolating between frames).
  430.    The DCT coefficients (of either the actual data, or the difference
  431.    between this block and the close match) are "quantized", which
  432.    means that you divide them by some value to drop bits off the
  433.    bottom end.  Hopefully, many of the coefficients will then end up
  434.    being zero.  The quantization can change for every "macroblock"
  435.    (a macroblock is 16x16 of Y and the corresponding 8x8's in both
  436.    U and V).  The results of all of this, which include the DCT
  437.    coefficients, the motion vectors, and the quantization parameters
  438.    (and other stuff) is Huffman coded using fixed tables.  The DCT
  439.    coefficients have a special Huffman table that is "two-dimensional"
  440.    in that one code specifies a run-length of zeros and the non-zero
  441.    value that ended the run.  Also, the motion vectors and the DC
  442.    DCT components are DPCM (subtracted from the last one) coded.
  443.  
  444. Q. So is each frame predicted from the last frame?
  445. A. No.  The scheme is a little more complicated than that.  There are
  446.    three types of coded frames.  There are "I" or intra frames.  They
  447.    are simply a frame coded as a still image, not using any past
  448.    history.  You have to start somewhere.  Then there are "P" or
  449.    predicted frames.  They are predicted from the most recently
  450.    reconstructed I or P frame.  (I'm describing this from the point
  451.    of view of the decompressor.)  Each macroblock in a P frame can
  452.    either come with a vector and difference DCT coefficients for a
  453.    close match in the last I or P, or it can just be "intra" coded
  454.    (like in the I frames) if there was no good match.
  455.  
  456.    Lastly, there are "B" or bidirectional frames.  They are predicted
  457.    from the closest two I or P frames, one in the past and one in the
  458.    future.  You search for matching blocks in those frames, and try
  459.    three different things to see which works best.  (Now I have the
  460.    point of view of the compressor, just to confuse you.)  You try using
  461.    the forward vector, the backward vector, and you try averaging the
  462.    two blocks from the future and past frames, and subtracting that from
  463.    the block being coded.  If none of those work well, you can intra-
  464.    code the block.
  465.  
  466.    The sequence of decoded frames usually goes like:
  467.  
  468.    IBBPBBPBBPBBIBBPBBPB...
  469.  
  470.    Where there are 12 frames from I to I (for US and Japan anyway.)
  471.    This is based on a random access requirement that you need a
  472.    starting point at least once every 0.4 seconds or so.  The ratio
  473.    of P's to B's is based on experience.
  474.  
  475.    Of course, for the decoder to work, you have to send that first
  476.    P *before* the first two B's, so the compressed data stream ends
  477.    up looking like:
  478.  
  479.    0xx312645...
  480.  
  481.    where those are frame numbers.  xx might be nothing (if this is
  482.    the true starting point), or it might be the B's of frames -2 and
  483.    -1 if we're in the middle of the stream somewhere.
  484.  
  485.    You have to decode the I, then decode the P, keep both of those
  486.    in memory, and then decode the two B's.  You probably display the
  487.    I while you're decoding the P, and display the B's as you're
  488.    decoding them, and then display the P as you're decoding the next
  489.    P, and so on.
  490.  
  491. Q. You've got to be kidding.
  492. A. No, really!
  493.  
  494. Q. Hmm.  Where did they get 352x240?
  495. A. That derives from the CCIR-601 digital television standard which
  496.    is used by professional digital video equipment.  It is (in the US)
  497.    720 by 243 by 60 fields (not frames) per second, where the fields
  498.    are interlaced when displayed.  (It is important to note though
  499.    that fields are actually acquired and displayed a 60th of a second
  500.    apart.)  The chrominance channels are 360 by 243 by 60 fields a
  501.    second, again interlaced.  This degree of chrominance decimation
  502.    (2:1 in the horizontal direction) is called 4:2:2.  The source
  503.    input format for MPEG I, called SIF, is CCIR-601 decimated by 2:1
  504.    in the horizontal direction, 2:1 in the time direction, and an
  505.    additional 2:1 in the chrominance vertical direction.  And some
  506.    lines are cut off to make sure things divide by 8 or 16 where
  507.    needed.
  508.  
  509. Q. What if I'm in Europe?
  510. A. For 50 Hz display standards (PAL, SECAM) change the number of lines
  511.    in a field from 243 or 240 to 288, and change the display rate to
  512.    50 fields/s or 25 frames/s.  Similarly, change the 120 lines in
  513.    the decimated chrominance channels to 144 lines.  Since 288*50 is
  514.    exactly equal to 240*60, the two formats have the same source data
  515.    rate.
  516.  
  517. Q. You didn't mention anything about the audio compression.
  518. A. Oh, right.  Well, I don't know as much about the audio compression.
  519.    Basically they use very carefully developed psychoacoustic models
  520.    derived from experiments with the best obtainable listeners to
  521.    pick out pieces of the sound that you can't hear.  There are what
  522.    are called "masking" effects where, for example, a large component
  523.    at one frequency will prevent you from hearing lower energy parts
  524.    at nearby frequencies, where the relative energy vs. frequency
  525.    that is masked is described by some empirical curve.  There are
  526.    similar temporal masking effects, as well as some more complicated
  527.    interactions where a temporal effect can unmask a frequency, and
  528.    vice-versa.
  529.  
  530.    The sound is broken up into spectral chunks with a hybrid scheme
  531.    that combines sine transforms with subband transforms, and the
  532.    psychoacoustic model written in terms of those chunks.  Whatever
  533.    can be removed or reduced in precision is, and the remainder is
  534.    sent.  It's a little more complicated than that, since the bits
  535.    have to be allocated across the bands.  And, of course, what is
  536.    sent is entropy coded.
  537.  
  538. Q. So how much does it compress?
  539. A. As I mentioned before, audio CD data rates are about 1.5 Mbits/s.
  540.    You can compress the same stereo program down to 256 Kbits/s with
  541.    no loss in discernable quality.  (So they say.  For the most part
  542.    it's true, but every once in a while a weird thing might happen
  543.    that you'll notice.  However the effect is very small, and it takes
  544.    a listener trained to notice these particular types of effects.)
  545.    That's about 6:1 compression.  So, a CD MPEG I stream would have
  546.    about 1.25 MBits/s left for video.  The number I usually see though
  547.    is 1.15 MBits/s (maybe you need the rest for the system data
  548.    stream).  You can then calculate the video compression ratio from
  549.    the numbers here to be about 26:1.  If you step back and think
  550.    about that, it's little short of a miracle.  Of course, it's lossy
  551.    compression, but it can be pretty hard sometimes to see the loss,
  552.    if you're comparing the SIF original to the SIF decompressed.  There
  553.    is, however, a very noticeable loss if you're coming from CCIR-601
  554.    and have to decimate to SIF, but that's another matter.  I'm not
  555.    counting that in the 26:1.
  556.  
  557.    The standard also provides for other bit rates ranging from 32Kbits/s
  558.    for a single channel, up to 448 Kbits/s for stereo.
  559.  
  560. Q. What's phase II?
  561. A. As I said, there is a considerable loss of quality in going from
  562.    CCIR-601 to SIF resolution.  For entertainment video, it's simply
  563.    not acceptable.  You want to use more bits and code all or almost
  564.    all the CCIR-601 data.  From subjective testing at the Japan
  565.    meeting in November 1991, it seems that 4 MBits/s can give very
  566.    good quality compared to the original CCIR-601 material.  The
  567.    objective of phase II is to define a bit stream optimized for these
  568.    resolutions and bit rates.
  569.  
  570. Q. Why not just scale up what you're doing with MPEG I?
  571. A. The main difficulty is the interlacing.  The simplest way to extend
  572.    MPEG I to interlaced material is to put the fields together into
  573.    frames (720x486x30/s).  This results in bad motion artifacts that
  574.    stem from the fact that moving objects are in different places
  575.    in the two fields, and so don't line up in the frames.  Compressing
  576.    and decompressing without taking that into account somehow tends to
  577.    muddle the objects in the two different fields.
  578.  
  579.    The other thing you might try is to code the even and odd field
  580.    streams separately.  This avoids the motion artifacts, but as you
  581.    might imagine, doesn't get very good compression since you are not
  582.    using the redundancy between the even and odd fields where there
  583.    is not much motion (which is typically most of image).
  584.  
  585.    Or you can code it as a single stream of fields.  Or you can
  586.    interpolate lines.  Or, etc. etc.  There are many things you can
  587.    try, and the point of MPEG II is to figure out what works well.
  588.    MPEG II is not limited to consider only derivations of MPEG I.
  589.    There were several non-MPEG I-like schemes in the competition in
  590.    November, and some aspects of those algorithms may or may not
  591.    make it into the final standard for entertainment video compression.
  592.  
  593. Q. So what works?
  594. A. Basically, derivations of MPEG I worked quite well, with one that
  595.    used wavelet subband coding instead of DCT's that also worked very
  596.    well.  Also among the worked-very-well's was a scheme that did not
  597.    use B frames at all, just I and P's.  All of them, except maybe one,
  598.    did some sort of adaptive frame/field coding, where a decision is
  599.    made on a macroblock basis as to whether to code that one as one
  600.    frame macroblock or as two field macroblocks.  Some other aspects
  601.    are how to code I-frames--some suggest predicting the even field
  602.    from the odd field.  Or you can predict evens from evens and odds
  603.    or odds from evens and odds or any field from any other field, etc.
  604.  
  605. Q. So what works?
  606. A. Ok, we're not really sure what works best yet.  The next step is
  607.    to define a "test model" to start from, that incorporates most of
  608.    the salient features of the worked-very-well proposals in a
  609.    simple way.  Then experiments will be done on that test model,
  610.    making a mod at a time, and seeing what makes it better and what
  611.    makes it worse.  Example experiments are, B's or no B's, DCT vs.
  612.    wavelets, various field prediction modes, etc.  The requirements,
  613.    such as implementation cost, quality, random access, etc. will all
  614.    feed into this process as well.
  615.  
  616. Q. When will all this be finished?
  617. A. I don't know.  I'd have to hope in about a year or less.
  618.  
  619. Q. How do I join MPEG?
  620. A. You don't join MPEG.  You have to participate in ISO as part of a
  621.    national delegation.  How you get to be part of the national
  622.    delegation is up to each nation.  I only know the U.S., where you
  623.    have to attend the corresponding ANSI meetings to be able to
  624.    attend the ISO meetings.  Your company or institution has to be
  625.    willing to sink some bucks into travel since, naturally, these
  626.    meetings are held all over the world.  (For example, Paris,
  627.    Santa Clara, Kurihama Japan, Singapore, Haifa Israel, Rio de
  628.    Janeiro, London, etc.)
  629.  
  630. Q. Well, then how do I get the documents, like the MPEG I draft?
  631. A. MPEG is a draft ISO standard. It's exact name is ISO CD 11172.
  632.    The draft consists of three parts: System, Video, and Audio. The
  633.    System part (11172-1) deals with synchronization and multiplexing
  634.    of audio-visual information, while the Video (11172-2) and Audio
  635.    part (11172-3) address the video and the audio compression techniques
  636.    respectively.
  637.  
  638.    You may order it from your national standards body (e.g. ANSI in
  639.    the USA) or buy it from companies like
  640.      OMNICOM
  641.      phone +44 438 742424
  642.      FAX +44 438 740154
  643.  
  644. ------------------------------------------------------------------------------
  645.  
  646. Subject: [72] What is wavelet theory?
  647.  
  648.  
  649. Preprints and software are available by anonymous ftp from the
  650. Yale Mathematics Department computer ceres.math.yale.edu[130.132.23.22],
  651. in pub/wavelets and pub/software.
  652.  
  653. epic is a pyramid wavelet coder. (For source code, see item 15 in part one).
  654.  
  655. Bill Press of Harvard/CfA has made some things available for anonymous
  656. ftp on cfata4.harvard.edu [128.103.40.79] in directory /pub. There is
  657. a short TeX article on wavelet theory (wavelet.tex, to be included in
  658. a future edition of Numerical Recipes), some sample wavelet code
  659. (wavelet.f, in FORTRAN - sigh), and a beta version of an astronomical
  660. image compression program which he is currently developing (FITS
  661. format data files only, in fitspress08.tar.Z).
  662.  
  663. An experimental wavelet decomposition program is available
  664. in linc.cis.upenn.edu:/pub/grasp/wavelet.tar.Z.
  665.  
  666. A mailing list dedicated to research on wavelets has been set up at the
  667. University of South Carolina. To subscribe to this mailing list, send a
  668. message with "subscribe" as the subject to wavelet@math.scarolina.edu.
  669.  
  670.  
  671. A 5 minute course in wavelet transforms, by Richard Kirk <rak@crosfield.co.uk>:
  672.  
  673. Do you know what a Haar transform is? Its a transform to another orthonormal
  674. space (like the DFT), but the basis functions are a set of square wave bursts
  675. like this...
  676.  
  677.    +--+                         +------+
  678.    +  |  +------------------    +      |      +--------------
  679.       +--+                             +------+
  680.  
  681.          +--+                                 +------+
  682.    ------+  |  +------------    --------------+      |      +
  683.             +--+                                     +------+
  684.  
  685.                +--+             +-------------+
  686.    ------------+  |  +------    +             |             +
  687.                   +--+                        +-------------+
  688.  
  689.                      +--+       +---------------------------+
  690.    ------------------+  |  +    +                           +
  691.                         +--+
  692.  
  693. This is the set of functions for an 8-element 1-D Haar transform. You
  694. can probably see how to extend this to higher orders and higher dimensions
  695. yourself. This is dead easy to calculate, but it is not what is usually
  696. understood by a wavelet transform.
  697.  
  698. If you look at the eight Haar functions you see we have four functions
  699. that code the highest resolution detail, two functions that code the
  700. coarser detail, one function that codes the coarser detail still, and the 
  701. top function that codes the average value for the whole `image'.
  702.  
  703. Haar function can be used to code images instead of the DFT. With bilevel
  704. images (such as text) the result can look better, and it is quicker to code.
  705. Flattish regions, textures, and soft edges in scanned images get a nasty
  706. `blocking' feel to them. This is obvious on hardcopy, but can be disguised on
  707. color CRTs by the effects of the shadow mask. The DCT gives more consistent
  708. results.
  709.  
  710. This connects up with another bit of maths sometimes called Multispectral
  711. Image Analysis, sometimes called Image Pyramids.
  712.  
  713. Suppose you want to produce a discretely sampled image from a continuous 
  714. function. You would do this by effectively `scanning' the function using a
  715. sinc function [ sin(x)/x ] `aperture'. This was proved by Shannon in the 
  716. `forties. You can do the same thing starting with a high resolution
  717. discretely sampled image. You can then get a whole set of images showing 
  718. the edges at different resolutions by differencing the image at one
  719. resolution with another version at another resolution. If you have made this
  720. set of images properly they ought to all add together to give the original 
  721. image.
  722.  
  723. This is an expansion of data. Suppose you started off with a 1K*1K image.
  724. You now may have a 64*64 low resolution image plus difference images at 128*128
  725. 256*256, 512*512 and 1K*1K. 
  726.  
  727. Where has this extra data come from? If you look at the difference images you 
  728. will see there is obviously some redundancy as most of the values are near 
  729. zero. From the way we constructed the levels we know that locally the average
  730. must approach zero in all levels but the top. We could then construct a set of
  731. functions out of the sync functions at any level so that their total value 
  732. at all higher levels is zero. This gives us an orthonormal set of basis 
  733. functions for a transform. The transform resembles the Haar transform a bit,
  734. but has symmetric wave pulses that decay away continuously in either direction
  735. rather than square waves that cut off sharply. This transform is the
  736. wavelet transform ( got to the point at last!! ).
  737.  
  738. These wavelet functions have been likened to the edge detecting functions
  739. believed to be present in the human retina.
  740.  
  741.  
  742. Loren I. Petrich <lip@s1.gov> adds that order 2 or 3 Daubechies
  743. discrete wavelet transforms have a speed comparable to DCT's, and
  744. usually achieve compression a factor of 2 better for the same image
  745. quality than the JPEG 8*8 DCT. (See item 25 in part 1 of this FAQ for
  746. references on fast DCT algorithms.)
  747.  
  748. ------------------------------------------------------------------------------
  749.  
  750. Subject: [73] What is the theoretical compression limit?
  751.  
  752.  
  753. There is no compressor that is guaranteed to compress all possible input
  754. files. If it compresses some files, then it must enlarge some others.
  755. This can be proven by a simple counting argument (see question 9).
  756.  
  757. As an extreme example, the following algorithm achieves 100%
  758. compression for one special input file and enlarges all other files by
  759. only one bit:
  760.  
  761. - if the input data is <insert your favorite one here>, output an empty file.
  762. - otherwise output one bit (zero or one) followed by the input data.
  763.  
  764. The concept of theoretical compression limit is meaningful only
  765. if you have a model for your input data. See question 70 above
  766. for some examples of data models.
  767.  
  768. ------------------------------------------------------------------------------
  769.  
  770. Subject: [74] Introduction to JBIG
  771.  
  772.  
  773. Written by Mark Adler <madler@cco.caltech.edu>.
  774.  
  775. JBIG losslessly compresses binary (one-bit/pixel) images.  (The B stands
  776. for bi-level.)  Basically it models the redundancy in the image as the
  777. correlations of the pixel currently being coded with a set of nearby
  778. pixels called the template.  An example template might be the two
  779. pixels preceding this one on the same line, and the five pixels centered
  780. above this pixel on the previous line.  Note that this choice only
  781. involves pixels that have already been seen from a scanner.
  782.  
  783. The current pixel is then arithmetically coded based on the eight-bit
  784. (including the pixel being coded) state so formed.  So there are (in this
  785. case) 256 contexts to be coded.  The arithmetic coder and probability
  786. estimator for the contexts are actually IBM's (patented) Q-coder.  The
  787. Q-coder uses low precision, rapidly adaptable (those two are related)
  788. probability estimation combined with a multiply-less arithmetic coder.
  789. The probability estimation is intimately tied to the interval calculations
  790. necessary for the arithmetic coding.
  791.  
  792. JBIG actually goes beyond this and has adaptive templates, and probably
  793. some other bells and whistles I don't know about.  You can find a
  794. description of the Q-coder as well as the ancestor of JBIG in the Nov 88
  795. issue of the IBM Journal of Research and Development.  This is a very
  796. complete and well written set of five articles that describe the Q-coder
  797. and a bi-level image coder that uses the Q-coder.
  798.  
  799. You can use JBIG on grey-scale or even color images by simply applying
  800. the algorithm one bit-plane at a time.  You would want to recode the
  801. grey or color levels first though, so that adjacent levels differ in
  802. only one bit (called Gray-coding).  I hear that this works well up to
  803. about six bits per pixel, beyond which JPEG's lossless mode works better.
  804. You need to use the Q-coder with JPEG also to get this performance.
  805.  
  806. Actually no lossless mode works well beyond six bits per pixel, since
  807. those low bits tend to be noise, which doesn't compress at all.
  808.  
  809. Anyway, the intent of JBIG is to replace the current, less effective
  810. group 3 and 4 fax algorithms.
  811.  
  812. ------------------------------------------------------------------------------
  813.  
  814. Subject: [99] Acknowledgments
  815.  
  816.  
  817. There are too many people to cite. Thanks to all people who directly
  818. or indirectly contributed to this FAQ.
  819.